import 'dart:convert';

import 'package:yun/entity/id_reader_entity.dart';
import 'package:yun/main.dart';

import '../entity/cpu_reader_entity.dart';

String currentVersion = '1.5.3';

String sendStatus({required String uuid,required String trade_no, required int light1,required int light2,required int door, }) {
  Map<String,dynamic> data = {
    "cmd": "100001",
    "data":{
      "h5": settingEntity.mode??0,
      "fan": 0,
      "door": door,
      "lamp": [light1, light2, 0],
      "time": {"of": settingEntity.offTime??'00:00', "on": settingEntity.onTime??'00:00'},
      "count": settingEntity.count??4,
      "region": settingEntity.region,
      "screen": settingEntity.screen??1,
      "version": currentVersion,
      "vol": [settingEntity.tipVolume, settingEntity.adVolume],
      "fanEndTime": "21:00",
      "temperature": 31,
      "fanStartTime": "07:00",
      "temperature_fan": 45,
      "temperature_low": 37,
      "temperature_high": 45,
    },
    "deviceID": settingEntity.deviceNo,
    "trade_no": trade_no,
    "uuid": uuid,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}

String sendStatusSelf({required int light1,required int light2,required int door, }) {
  Map<String,dynamic> data = {
    "cmd": "100001",
    "data":{
      "fan": 0,
      "h5": settingEntity.mode??0,
      "door": door,
      "lamp": [light1, light2, 0],
      "time": {"of": settingEntity.offTime??'00:00', "on": settingEntity.onTime??'00:00'},
      "count": settingEntity.count??4,
      "region": settingEntity.region,
      "screen": settingEntity.screen??1,
      "version": currentVersion,
      "vol": [settingEntity.tipVolume, settingEntity.adVolume],
      "fanEndTime": "21:00",
      "temperature": 31,
      "fanStartTime": "07:00",
      "temperature_fan": 45,
      "temperature_low": 37,
      "temperature_high": 45,
    },
    "deviceID": settingEntity.deviceNo,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}

String setScanTime({required String uuid,required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": "700000",
    "uuid": uuid,
    "state": 1,
    "deviceID": settingEntity.deviceNo,
    "trade_no": trade_no,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
// String inventoryRfidWithDelayed({required List rfid,required String uuid, required String trade_no}) {
//   Map<String,dynamic> data = {
//     "cmd": "101001",
//     "uuid": uuid,
//     "state": 2,
//     "delayed": 500,
//     "deviceID": settingEntity.deviceNo,
//     "trade_no": trade_no,
//     "rfid": rfid,
//     "deviceVersion":"xy_$currentVersion"
//   };
//   return json.encode(data);
// }
String inventoryRfid({required String cmd,required dynamic state,required List rfid,required String uuid, required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": cmd,
    "uuid": uuid,
    "state": state,
    "deviceID": settingEntity.deviceNo,
    "trade_no": trade_no,
    "rfid": rfid,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
// String inventoryRfidAfterCloseDoor({required List rfid,required String uuid, required String trade_no}) {
//   Map<String,dynamic> data = {
//     "cmd": "101003",
//     "uuid": uuid,
//     "state": 1,
//     "deviceID": settingEntity.deviceNo,
//     "trade_no": trade_no,
//     "rfid": rfid,
//     "deviceVersion":"xy_$currentVersion"
//   };
//   return json.encode(data);
// }

String sendCloseDoor({required String uuid, required String trade_no, required int state}) {
  Map<String,dynamic> data = {
    "cmd": "101031",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "state":state,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String sendOpenDoor({required String uuid, required String trade_no, required int state}) {
  Map<String,dynamic> data = {
    "cmd": "101002",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "state":state,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String sendLight({required String uuid, required String trade_no, required int state, required int lamp}) {
  Map<String,dynamic> data = {
    "cmd": "102001",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "state":state,
    "lamp":lamp,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String sendVoice({required String uuid, required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": "105001",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "state":1,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String sendBlock({required String uuid, required String trade_no, required String block, required String rfid}) {
  Map<String,dynamic> data = {
    "cmd": "103002",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "data":block,
    "rfid":rfid,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String sendRestart({required String uuid}) {
  Map<String,dynamic> data = {
    "cmd": "200000",
    "uuid": uuid,
    // "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "state":1,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String sendScreenOff({required String uuid,required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": "200010",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "state":1,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String sendScreenOn({required String uuid,required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": "200011",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "state":1,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String sendDownload({required String uuid,required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": "400000",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}

String volume({required String uuid,required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": "105002",
    "uuid": uuid,
    "trade_no": trade_no,
    "state": 1,
    "deviceID": settingEntity.deviceNo,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}

String alarm({required String uuid,required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": "200001",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String h5({required String uuid,required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": "800000",
    "uuid": uuid,
    "state":1,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String ad({required String uuid,required String trade_no}) {
  Map<String,dynamic> data = {
    "cmd": "800001",
    "uuid": uuid,
    "state":1,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String update({required String uuid,required String trade_no,required String version,required String state}) {
  Map<String,dynamic> data = {
    "cmd": "500000",
    "uuid": uuid,
    "trade_no": trade_no,
    "deviceID": settingEntity.deviceNo,
    "state":1,
    "version":version,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}
String sendDownloadSuccess({required String url}) {
  Map<String,dynamic> data = {
    "cmd": "300002",
    "url": url,
    "deviceID": settingEntity.deviceNo,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}

String sendIdReader({required IdReaderEntity entity}) {
  Map<String,dynamic> data = {
    "cmd": "300000",
    "card": {
      "id": entity.id,
      "sex": entity.sex,
      "name": entity.name,
      "type": 0,
      "nation": entity.nation,
      "office": entity.office,
      "address": entity.address,
      "endTime": entity.endTime,
      "birthday": entity.birthday,
      "startTime": entity.startTime
    },
    "deviceID": settingEntity.deviceNo,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}


String sendCpuReader({required CpuReaderEntity entity}) {
  Map<String,dynamic> data = {
    "cmd": "300004",
    "card": {
      "name": entity.name,
      "SSNum": "330621198601050000",
      "cardNum": "GA3226526",
      "issuingDate": "20230731",
      "terminalNum": "330700922863",
      "cardResetInfo": "00814A444686603307060EE042",
      "expirationDate": "20330731",
      "terminalDeviceNum": "00010900202108002545",
      "cardCanonicalVersion": "3.00",
      "cardIdentificationCode": "330700D156000005060EE04269B9C59B",
      "administrativeDivisionCodeOfIssuingArea": "330700"
    },
    "deviceID": settingEntity.deviceNo,
    "deviceVersion":"xy_$currentVersion"
  };
  return json.encode(data);
}



